package com.wl.dzt.sys.core.dao.tree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wl_code@163.com
 * @version 1.0
 * @date 2018/7/5/005
 * @description 树形节点
 * 用于适配树形节点所需要的数据
 */
public class TreeNode {
    /**
     * 编号
     */
    private String id;
    /**
     * 节点名称
     */
    private String text;
    /**
     * 上级id
     */
    private String parentId;
    /**
     * 扩展字段map
     */
    private Map<String, Object> expansions = new HashMap<String, Object>();
    /**
     * 子节点
     */
    private List<Map<String, Object>> childrens = new ArrayList<Map<String, Object>>();
    /**
     * 是否为子节点
     */
    private boolean leaf = true;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public Map<String, Object> getExpansions() {
        return expansions;
    }

    public void setExpansions(Map<String, Object> expansions) {
        this.expansions = expansions;
    }

    public List<Map<String, Object>> getChildrens() {
        return childrens;
    }

    public void setChildrens(List<Map<String, Object>> childrens) {
        this.childrens = childrens;
    }

    public boolean isLeaf() {
        return leaf;
    }

    public void setLeaf(boolean leaf) {
        this.leaf = leaf;
    }

    /**
     * <b>将树形节点对象转换为map</b>
     * <p>
     * 构建树形的过程中需要使用map提高灵活性</br>
     * </p>
     */
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.putAll(this.expansions);
        map.put("id", this.id);
        map.put("text", this.text);
        map.put("leaf", this.leaf);
        // map.put("expanded", "root".equalsIgnoreCase(this.parentId));
        map.put("expanded", true);
        map.put("children", this.childrens);
        return map;
    }

    public Map<String, Object> getMap() {
        return toMap();
    }
}
